#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/moduleparam.h>
#include<linux/unistd.h>
#include<linux/sched.h>
#include<asm/uaccess.h>
#include<asm/cacheflush.h>

#define DIR_SYS_CALL_TABLE 0xc0318500
void **sys_call_table = (void *) DIR_SYS_CALL_TABLE;
asmlinkage int (*sys_call_orig) (const char *pathname);
struct page *pg;
pgprot_t prot;

int hacked_mkdir(const char *path){
	printk(KERN_ALERT "Thou shalt not make dirs!\n");
	return 0;
}

static int __init init_mkdirhack(void){
	//guardo la syscall original
	sys_call_orig = sys_call_table[__NR_mkdir];
	//modifico los permisos de escritura de la pagina
	pg = virt_to_page( DIR_SYS_CALL_TABLE );
	prot.pgprot = VM_READ | VM_WRITE | VM_EXEC;
	change_page_attr(pg, 1, prot);
	//reemplazo la syscall por mi funcion
	sys_call_table[__NR_mkdir] = hacked_mkdir;
	return 0;
}

static void __exit exit_mkdirhack(void){
	sys_call_table[__NR_mkdir] = sys_call_orig;
}

MODULE_LICENSE("GPL");
module_init(init_mkdirhack);
module_exit(exit_mkdirhack);

